/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/


#pragma once

#include <stack>

/*-----------------------------------------------------------------------------
	Debug scene :
-----------------------------------------------------------------------------*/

class EDVScene : public IDVScene {
	public:
							EDVScene		( ERenderSystem *rs );
							~EDVScene		( void );
				
		virtual void		ReloadShaders	( void );
		virtual void		SetView			( const EPoint &position, const EQuaternion &orient );
		virtual void		SetProjection	( float znear, float zfar, float width, float height );
		virtual void		DrawLine		( const ERSLine_s &line );
		virtual void		RenderScene		( void );

		virtual void		DrawPoint		( const EPoint &origin, float size, const EColor &color ); 
		virtual void		DrawArrow		( const EPoint &origin, const EVector &dir, float scale, const EColor &color ); 
		virtual void		DrawBox			( const EBBox &bbox, const EColor &color );

		virtual void		PushWorldMatrix	( void );
		virtual void		MulWorldMatrix	( const EMatrix world );
		virtual void		MulWorldMatrix	( const EPoint &position, const EQuaternion &orient );
		virtual void		PopWorldMatrix	( void );

		static	void		InitLuaAPI	( void );
		
	protected:
		static int		setColor	( lua_State *L );	//	r,g,b,a=1
		static int		drawLine	( lua_State *L );	//	xyz1, xyz2
		static int		drawArrow	( lua_State *L );	//	xyz1, dir2, s
		static int		drawPoint	( lua_State *L );	//	xyz1, size
		static int		drawBox		( lua_State *L );	//	corners: p1, p2
		
		EColor			current_color;
	
		ERenderSystem	*rs;
		IPxRSDriver		driver;
		IPxFXManager	fxm;
		IPxVBManager	vbm;

		EPoint			position;		
		EMatrix		matrix_view;
		EMatrix		matrix_proj;

		stack<EMatrix>	matrix_stack;		
		EMatrix			matrix_world;
		
		std::vector<ERSLine_s>	lines;
		
		IPxEffect		effect;

		static EDVScene	*self;
	};